package servlet;

import pojo.Time;
import service.TimeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
/**
 *2022.3.16测试完成，由李红玉编写
 * 日期时间新增
 */
@WebServlet(name = "TimeInsertServlet", value = "/TimeInsertServlet")
public class TimeInsertServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        this.doPost(req,resp);
    }


    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        resp.setContentType("text/html; charset=utf-8");
        PrintWriter out=resp.getWriter();
        TimeService timeservice=new TimeService();

        //保存结果变量
        int save=0;
        //实体类
        Time time=new Time();
        time.setClassTime("2022-3-10");
        time.setRemarks("暂无");

        try {
            save=timeservice.insert(time);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        out.println(save);
    }
}
